package com.study.servlet.request;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* @Name: GetRequestBaseInfo
* @Description: 使用Request对象获取http请求主机基本信息
* @Author: 李超	lc_jack@foxmail.com
* @CreateDate: 2017-3-1 下午3:36:01 
* @Version: V1.0
 */
public class GetRequestBaseInfo extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String method = request.getMethod() ;
		System.out.println("客户机请求方式：" + method);
		String remoteAddr = request.getRemoteAddr() ;
		System.out.println("客户端ip地址：" + remoteAddr);
		String remoteHost = request.getRemoteHost() ;
		System.out.println("客户端完整主机名：" + remoteHost);
		int remotePort = request.getRemotePort() ;
		System.out.println("客户端请求所使用的网络端口号：" + remotePort);
		StringBuffer requestURL = request.getRequestURL() ;
		System.out.println("客户端请求URL(协议+主机+端口号+应用名称+请求资源路径)：" + requestURL);
		String requestURI = request.getRequestURI() ;
		System.out.println("客户端请求URI(应用名称+请求资源路径)：" + requestURI);
		String localAddr = request.getLocalAddr() ;
		System.out.println("服务器ip地址：" + localAddr);
		String localName = request.getLocalName() ;
		System.out.println("服务器主机名称：" + localName);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doGet(request, response);
	}

}
